package com.huluobo.a2203parkdemo.login

import android.util.Log
import androidx.lifecycle.MutableLiveData
import com.huluobo.base.bean.LoginBean
import com.huluobo.base.db.UserDao
import com.huluobo.base.mvvm.BaseViewModel
import com.huluobo.base.net.ApiService
import com.huluobo.base.net.ApiServiceLogin
import dagger.hilt.android.lifecycle.HiltViewModel
import okhttp3.RequestBody
import javax.inject.Inject

/**
 *  Created by LC on 2024/7/25.
 */
@HiltViewModel
class LoginViewModel @Inject constructor(
    val apiService: ApiServiceLogin,
    val userDao: UserDao
) : BaseViewModel() {
    val onLoginSuccess by lazy { MutableLiveData<String>() }

    fun login(body: RequestBody) {
        executeNetRequest(
            {
                apiService.login(body)
            },
            onLoginSuccess::postValue
        )
    }

    val insertUserComplete by lazy { MutableLiveData<String>() }
    fun insertUser(loginBean: LoginBean) {
        executeDb(
            {
                userDao.insertUserInfo(loginBean)
                "添加成功"
            },
            insertUserComplete::postValue
        )
    }
}